/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2010-12-26 下午07:51:37
 *
 * SendMailJob.java 
 *
 *******************************************************************/
package com.transer.job;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.transer.mail.Mail;
import com.transer.persistance.bean.User;
import com.transer.template.MailTemplateBuilder;
import com.transer.utils.ResourceBundleUtils;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class SendMailJob implements Runnable {
	// 收件人
	private User user;

	public SendMailJob(User mailTo) {
		this.user = mailTo;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		try {
			// 模板参数
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("account", user.getNikeName());
			param.put("email", user.getEmail());
			param.put("activeURI", ResourceBundleUtils.getStringValue("active.url", new String[] { user.getEmail(), user.getActiveCode() }));
			// 构建模板内容
			String content = MailTemplateBuilder.build("mail.ftl", param);
			// 构建邮件
			Mail mail = new Mail(ResourceBundleUtils.getStringValue("mail.title", null), content);
			// 设置邮件来处
			mail.addFrom(ResourceBundleUtils.getStringValue("mail.from", null));
			// 设置收件人
			mail.addMailTo(user.getEmail());
			// 发送邮件
			mail.sendMail();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("邮件发送失败", e);
		} finally {
		}
	}

	private static final Logger logger = Logger.getLogger(SendMailJob.class);
}
